﻿
using RTW.DAL;
using RTW.OA.Models;
using RTW.Utils.Utils;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace RTW.OA.Areas.System.Servers
{
    public class FlowServers
    {
	    private readonly IRepository<wf_flowinfo> wf_flowinfoRepository;

        public FlowServers()
        {
            wf_flowinfoRepository = new DapperRepository<wf_flowinfo>();

        }

        public List<wf_flowinfo> GetData()
        {
            return wf_flowinfoRepository.GetAllEnumerable().ToList();
        }

        public wf_flowinfo GetModelById(string id)
        {
            return wf_flowinfoRepository.GetById(id);
        }

		
        internal void Add(wf_flowinfo model)
        {
            wf_flowinfoRepository.Insert(model);
        }

        internal void Update(wf_flowinfo model)
        {
            wf_flowinfoRepository.Update(model);
        }

		internal void Del(string id)
        {
            wf_flowinfoRepository.DeleteByIds(id);
        }

				   //部门   
        internal List<SelectListItem> GetTYPEID()
        {
            List<SelectListItem> tables = new List<SelectListItem>();
            var dstable = wf_flowinfoRepository.SqlWithParamsDynamic("select a.DEPT_NAME Value,concat(a.DEPT_NAME,'-----',convert(nvarchar(max),a.DEPT_ID)) Text from department a");
            tables.Clear();
            tables.Add(new SelectListItem() { Value = "0", Text = "无父级部门" });
            foreach (var dr in dstable)
            {
                string Id = dr.Value.ToString();
                string Title = dr.Text.ToString().Trim();
                int ClassLayer = 1;// int.Parse(dr.LEVEL.ToString());
                
                if (ClassLayer == 0)
                {
                    tables.Add(new SelectListItem { Value = Id, Text = Title });
                }
                else
                {
                    Title = "├ " + Title;
                    Title = StringUtil.StringOfChar(ClassLayer, "　") + Title;
                    tables.Add(new SelectListItem { Value = Id, Text = Title });
                }
            }

            return tables;
        }


                   //流程分类
        internal List<SelectListItem> GetTYPE()
        {
            List<SelectListItem> tables = new List<SelectListItem>();
            var dstable = wf_flowinfoRepository.SqlWithParamsDynamic("select a.CODE_ID Value,concat(a.CODE_NAME,'-----',a.CODE_NO) Text from sys_code  a  where PARENT_NO=3");
            tables.Clear();

            foreach (var dr in dstable)
            {
                string Id = dr.Value.ToString();
                string Title = dr.Text.ToString().Trim();
                tables.Add(new SelectListItem { Value = Id, Text = Title });
            }

            return tables;
        }


                   
        internal List<SelectListItem> GetFORMID()
        {
            List<SelectListItem> tables = new List<SelectListItem>();
            var dstable = wf_flowinfoRepository.SqlWithParamsDynamic("select a.ID Value,a.name Text from wf_forminfo a");
            tables.Clear();

            foreach (var dr in dstable)
            {
                string Id = dr.Value.ToString();
                string Title = dr.Text.ToString().Trim();
                tables.Add(new SelectListItem { Value = Id, Text = Title });
            }

            return tables;
        }


    }
}